# -*- coding:utf-8 -*-
# 黑cyc宇
from flask import Flask
from .kernel.plugin import Plugin, load_plugin, load_plugins
import os

def register_parse(bot):
    from bot.kernel.parse_handler import route_parse_handler
    bot.register_blueprint(route_parse_handler)

def load_setting(bot):
    bot.config.from_pyfile('config/env.py')
    bot.config.from_pyfile('config/bot.py')
    bot.config.from_pyfile('setting_test.py')


def init_bot(bot):
    from bot.kernel.notice_request import on_command, on_notice, on_request
    bot.cmd_route = {"command": [], "notice": [], "request": []}
    bot.on_command = on_command(bot)
    bot.on_notice = on_notice(bot)
    bot.on_request = on_request(bot)

    from bot.kernel.plugin import load_plugins, load_plugin, Plugin
    plugin_dir = os.path.join(os.path.dirname(__file__), 'plugins')
    load_plugins(bot, plugin_dir, 'bot.plugins')
def init_other(app):
    app.ret_msg_dict = {0: 0}

def create_bot():
    bot = Flask(__name__)
    load_setting(bot)  # 引入配置
    init_bot(bot)
    register_parse(bot)
    init_other(bot)
    return bot
